package bidsanity

import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class CustomerControllerIntegrationTests {
    @Before
    void setUp() {
        // Setup logic here
    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testDeleteCustomer() {
        def controller = new CustomerController()
        def admin = new Customer(emailAddress: 'admin@example.org', password: "testing", isAdmin: true).save(validate: true, flush: true)
        controller.session.user = admin.emailAddress
        def s = new Customer(emailAddress: 'seller@example.org', password: "testing").save(validate: true, flush: true)
        def l = new Listing(
                name: 'TestListing',
                endDate: new Date() + 10,
                startingBidPrice: 1.0D,
                description: 'a test listing',
                seller: s).save(validate: true, flush: true)
        s.save(validate: true, flush: true)
        Assert.assertTrue(Listing.findAllBySeller(s).size() > 0)
        Map myParams = [id:s.id]
        controller.params.putAll(myParams)
        controller.delete()
        Assert.assertTrue(controller.flash.message == "Customer with email ${s.emailAddress} could not be deleted due to existing listing(s)")
        Assert.assertTrue(controller.response.redirectedUrl == "/customer/show/${s.id}")
    }

}
